﻿using AutoMapper;
using System;

namespace AutoMapperProj
{

    /**
            官网文档：
                https://docs.automapper.org/en/stable/Getting-started.html
     */
    class Program
    {
        static void Main(string[] args)
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap<Foo, FooDto>();
                cfg.CreateMap<Bar, BarDto>()
                .ForMember(d => d.bid, opt => opt.MapFrom(s => s.id))
                .ForMember(d => d.bar_name, opt => opt.MapFrom(s => s.name));
            });

#if DEBUG
            configuration.AssertConfigurationIsValid();
#endif

            var mapper = configuration.CreateMapper();

            var fooDto = mapper.Map<FooDto>(new Foo() { id = 1, name = "foo", added = DateTime.Now });

            var barDto = mapper.Map<BarDto>(new Bar() { id = 1, name = "bar", added = DateTime.Now });


            var fooDto2 = mapper.Map<Foo>(new FooDto() { id = 1, name = "foo", added = DateTime.Now });

            var barDto2 = mapper.Map<Bar>(new BarDto() { bid = 1, bar_name = "bar", added = DateTime.Now });

        }
    }

    public class Foo
    {
        public long id { get; set; }
        public string name { get; set; }
        public DateTime added { get; set; }

    }
    public class FooDto
    {
        public long id { get; set; }
        public string name { get; set; }
        public DateTime added { get; set; }
    }
    public class Bar
    {
        public long id { get; set; }
        public string name { get; set; }
        public DateTime added { get; set; }
    }
    public class BarDto
    {
        public long bid { get; set; }
        public string bar_name { get; set; }
        public DateTime added { get; set; }
    }
}
